const app = getApp();
const Url = app.globalData.Url
let over = 7
Page({
  /**
   * 页面的初始数据
   */
  data: {
    // 显示遮罩？
    isshow: true,
    //数据
    params: [],
    hasmoreData: true
  },
  // 设置显示遮罩
  show_modal: function(e) {
    let index = e.currentTarget.dataset.index;
    let arr = this.data.params;
    let arrCut = 'params[' + index + '].cut'
    this.setData({
      [arrCut]: true,
      listIndex: index
    })
  },
  hideModal: function(e) {
    let index = e.currentTarget.dataset.index;
    let arr = this.data.params;
    let arrCut = 'params[' + index + '].cut'
    this.setData({
      [arrCut]: false,
    })
  },
  // 以下是每个表单数据的值的监听
  recipients: function(e) {},
  telphone: function(e) {},
  detail_address: function(e) {},
  // 设置picker表单值
  bindRegionChange: function(e) {
    let index = e.currentTarget.dataset.index;
    let arr = this.data.params;
    let arrRegion = 'params[' + index + '].region'
    this.setData({
      [arrRegion]: e.detail.value
    })
    console.log(this.data.params[0].region)
  },
  // .....修改.......
  Submit: function(e) {
    console.log(e)
    let params = {
      KDReceiverID: '',
      ReceiverName: '',
      ReceiverMobile: '',
      ProvinceID: '',
      CityID: '',
      AreaID: '',
      ReceiverAddr: '',
      ReceiverCompany: '',
      CreateTime: ''
    }
    wx.request({
      url: Url + '/baimi/user/express/modUserReceiver',
      method: 'PUT',
      data: {
        data: params
      },
      header: {
        'content-type': 'application/josn'
      },
      success: function(res) {
        console.log(res);
        if (res.code == 1) {
          // 跳转到信息填写详情页
          wx.navigateTo({
            url: 'test' //请填地址
          })

        }
      },
      fail: function() {}
    })
  },
  Back: function() {
    wx.navigateBack({
      delta: 1
    })
  },
  addPerson: function() {
    wx.navigateTo({
      url: 'add'
    })
  },
  // 点击删除联系人
  delete_recipients: function(e) {
    console.log(e)
    wx.request({
      url: Url + '/baimi/user/express/deleteUserReceiver',
      method: 'DELETE',
      data: {
        UserID: UserID,
        KDReceiverID: KDReceiverID
      },
      header: {
        'content-type': 'application/josn'
      },
      success: res => {
        console.log(res)
      }
    })
  },
  over: function() {
    return
  },
  //加载更多
  loadMore: function() {
    let data = {
      region: ['广东省', '广州市', '海珠区'],
      customItem: '全部',
      recipients_name: '廖宝锋',
      tel_num: '15629120083',
      address: '爱了就爱了放假咯了房间卡路附近卡路附近',
    }
    let array = [];
    over++;
    for (let i = 0; i < over; i++) {
      array.push(data)
    }
    this.setData({
      params: array
    })
    wx.showToast({
      title: '加载中', //提示语
      icon: 'loading', //icon: success/loading/none
      duration: 1000, //规定自动关闭的时间
      make: true
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    //   var UserID = "201701031229AA";
    //   wx.request({
    //     url: '', //此处为进入页面数据的请求渲
    //     data: {
    //     },
    //     success: function(res) {
    //     }
    //   })
    let data = {
      region: ['广东省', '广州市', '海珠区'],
      customItem: '全部',
      recipients_name: '廖宝锋',
      tel_num: '15629120083',
      address: '爱了就爱了放假咯了房间卡路附近卡路附近',
    }
    let array = [];
    for (let i = 0; i < 6; i++) {
      array.push(data)
    }
    this.setData({
      params: array
    })
  },
  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    over = 7;
    let data = {
      region: ['广东省', '广州市', '海珠区'],
      customItem: '全部',
      recipients_name: '廖宝锋',
      tel_num: '15629120083',
      address: '爱了就爱了放假咯了房间卡路附近卡路附近',
    }
    let array = [];
    for (let i = 0; i < 6; i++) {
      array.push(data)
    }
    this.setData({
      hasmoreData: true,
      params: array,
    })
    wx.showToast({
      title: '加载中', //提示语
      icon: 'loading', //icon: success/loading/none
      duration: 1000, //规定自动关闭的时间
      make: true
    })
    wx.stopPullDownRefresh();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    if (over < 10) {
      this.loadMore();
    } else {
      this.setData({
        hasmoreData: false
      })
    }
  },
})